package com.edu.deadlock;

public class DeadLock_ {

    public static void main(String[] args) {


        T t1 = new T();
        t1.flag = true;

        T t2 = new T();
        t2.flag = false;

        t1.start();
        t2.start();
    }
}

class T extends Thread{
    boolean flag =true;
    static  Object a = new Object();
    static  Object b = new Object();
    @Override
    public  void run() {
        if (flag){
            synchronized (a){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (b){

                }
            }
        }else {
            synchronized (b){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (a){

                }
            }
        }


    }
}
